<template>
    <div id="account">
        <Breadcrumb :pathContent="content"/>
        <el-form :model="AdminUserAddRequest" ref="AdminUserAddRequest" label-width="100px" class="demo-ruleForm">
        <div class="information-page">
                <el-form-item class="information-title">
                    <h1>基础信息</h1>
                </el-form-item>
                <div class="basic-information">
                <div class="information-left-page">
                    <el-form-item label="登录账号" :required="true">
                        <el-input v-model="AdminUserAddRequest.account" placeholder="请输入账号"></el-input>
                    </el-form-item>
                    <div style="overflow: hidden;">
                        <div class="information-left">
                            <el-form-item label="姓名" :required="true">
                                <el-input v-model="AdminUserAddRequest.name" placeholder="请输入姓名"></el-input>
                            </el-form-item>
                        </div>
                        <div class="information-right">
                            <el-form-item label="手机" :required="true">
                                <el-input v-model="AdminUserAddRequest.mobile" placeholder="请输入手机号码"></el-input>
                            </el-form-item>
                        </div>
                    </div>
                    <el-form-item label="部门" :required="true">
                        <el-cascader
                          :options="depts"
                          :props="{ value: 'id', label: 'department', children: 'adminDepartments' }"
                          v-model="dept"
                          filterable
                          change-on-select
                          :show-all-levels="false">
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="职位">
                        <el-input v-model="AdminUserAddRequest.position" placeholder="请输入职位"></el-input>
                    </el-form-item>
                    <el-form-item label="部门负责人" style="text-align: left;">
                        <el-radio-group v-model="AdminUserAddRequest.responsible">
                        <el-radio :label="1">是</el-radio>
                        <el-radio :label="0">否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <div class="information-left">
                        <el-form-item label="Email">
                            <el-input v-model="AdminUserAddRequest.email" placeholder="请输入邮箱"></el-input>
                        </el-form-item>
                    </div>
                    <div class="information-right">
                        <el-form-item label="QQ">
                            <el-input v-model="AdminUserAddRequest.qq" placeholder="请输入QQ号码"></el-input>
                        </el-form-item>
                    </div>
                </div>
                </div>
                <el-form-item class="information-title page-title">
                    <h1>账号权限<label style="color: rgb(145, 160, 177); font-size: 12px; font-weight: 300; margin-left: 30px;">权限与角色关联, 这样该账号的角色可完成权限设置</label></h1>
                </el-form-item>
                <el-form-item label="账号权限" class="group-page">
                    <el-checkbox-group v-model="AdminUserAddRequest.roleId" style="text-align: left;">
                      <div v-for="item in roleName" class="role" :key="item.id">
                        <el-checkbox :label="item.id" :key="item.id" name="type">{{item.name}}</el-checkbox>
                      </div>
                    </el-checkbox-group>
                </el-form-item>
            </div>
          <div class="information-btn">
            <el-form-item>
                <el-button type="primary" @click="saveAccount">保存</el-button>
                <el-button @click="back">取消</el-button>
            </el-form-item>
          </div>
        </el-form>
    </div>
</template>
<script>
import { getRoleList, getDeptstaffAll, addStaff } from '../../../public/js/setting'
const ButtonFooter = () => import('@/components/common/ButtonFooter')
const Breadcrumb = () => import('@/components/common/Breadcrumb')
export default {
  name: 'AddAccount',
  data () {
    return {
      content: {
        firstTitle: '设置',
        secondTitle: '新增账号',
        type: 'close'
      },
      AdminUserAddRequest: {
        'timestamp': 0,
        'version': 'string',
        'operation': 'string',
        'name': '',
        'account': '',
        'mobile': '',
        'dept': '',
        'email': '',
        'qq': '',
        'position': '',
        'responsible': '',
        'roleId': []
      },
      number: [],
      dept: [],
      depts: [],
      roleName: []
    }
  },
  created () {
    getRoleList().then(res => {
      this.roleName = res.data.adminRoles
    })
    getDeptstaffAll().then(res => {
      this.depts = res.data.adminDepartments
    })
  },
  methods: {
    cancel () {
      this.$router.push('/index/staff')
    },
    saveAccount () {
      this.AdminUserAddRequest.dept = this.dept[this.dept.length - 1]
      console.log('this.AdminUserAddRequest', this.AdminUserAddRequest)

      addStaff(this.AdminUserAddRequest).then(res => {
        if (res.data.errCode === 0) {
          this.$message.success('新增成功')
          this.$router.go(-1)
        }
      })
    },
    back () {
      this.$router.go(-1)
    }
  },
  components: {
    ButtonFooter,
    Breadcrumb
  }
}
</script>
<style lang="scss">
   #account {
    margin-bottom: 63px;
    .el-cascader {
      width: 100%;
    }
  }
  .role {
    float: left;
    margin-right: 20px;
  }
  .information-page {
    background: white;
    margin-top: 10px;
  }
  .page-title, .title {
    margin-bottom: 0;
  }

  .group-page {
    margin-bottom: 0;
    .el-checkbox-group {
      float: left;
      margin-right: 20px;
    }
  }

  .foo-warpper {
    padding: 0 20px 20px 20px;
  }

  .information-page {
    padding: 20px;
    .basic-information, .account-permissions {
      overflow: hidden;
      .information-left-page {
        width: 47%;
        float: left;
      }
      .information-right-page {
        width: 47%;
        float: right;
      }
    }
    .basic-information {
      .information-left-page {
        .information-title {
          .el-form-item__content {
            margin-left: 0!important;
          }
        }
        .area {
          text-align: left;
        }
      }
    }
    h1 {
      color: #45a2ff;
      text-align: left;
    }
  }

  .h-eight {
    height: 130px;
  }
  .line-h {
    width: 6%;
    line-height: 130px;
    text-align: center;
    border-right: 1px solid #e6e6e6;
  }
  .line-b-h {
    width: 4.5%;
    line-height: 4.5;
    border-right: 1px solid #e6e6e6;
  }
  .padding-b {
    line-height: 2;
    padding-bottom: 17px;
  }
  .padding-t {
    width: 73.4%;
    line-height: 2;
    padding-top: 22px;
    border-bottom: 1px solid #e6e6e6;
  }
  .hotel-l-bg {
    background-color: #eef1f9;
  }

  .el-select>.el-input {
    display: inline-block;
  }

  .information-left {
    width: 50%;
    float: left;
  }
  .information-right {
    width: 50%;
    float: left;
  }
  .information-title {
    .el-form-item__content {
      margin-left: 0!important;
    }
  }

  .complexity {
    text-align: left;
    overflow: hidden;
    span {
      margin-top: 5px;
      line-height: 2;
      color: white;
      padding: 0 40px;
      text-align: center;
      display: inline-block;
      background-color: #e9ecf3;
      float: left;
      margin-right: 2px;
      font-size: 12px;
    }
  }
  .passwordbg {
    background-color: #1f88f0!important;
  }

  .add-account .el-form .el-form-item label {
    text-align: right;
  }

  .information-btn {
    padding: 20px 0px 20px 55px;
    text-align: left;
    position: fixed;
    bottom: 0;
    background-color: white;
    box-shadow: 0px -1px 4px rgba(0,0,0,0.4);
    width: 79.7%;
    z-index: 1000;
    .el-form-item {
      margin-bottom: 0;
      .el-form-item__content {
        margin-left: 0!important;
      }
    }
  }
  .el-tabs__header {
    margin: 0px;
}
</style>
